package at.ac.tuwien.sepm.s2011.e0208329.dao;

//import java.sql.*;
//import java.util.*;
//import java.util.List;
import javax.swing.*;

import java.awt.*;
//import java.awt.event.ActionEvent;
//import java.awt.event.ActionListener;

//import at.ac.tuwien.sepm.s2011.e0208329.domain.*;
import at.ac.tuwien.sepm.s2011.e0208329.gui.*;

public class TestConn{
	static JFrame appFrame;
	static Container cPane;
	static ItemDao itemDao;
	
	
    public static void main(String[] args) throws Exception     
    {         
    	HsqldbConn con = new HsqldbConn();  
    	con.openConn("YKK");              // setup Connection
    	itemDao = new JDBCItemDao(con);    //build up the Dao-Object
    	//List<Item> listIt = new ArrayList<Item>();
    	
    	CreateGUI gui = new CreateGUI(itemDao);
    	gui.arrangeComponents();
    	
    	/*
    	//test update function to Invoice
    	con.update("INSERT INTO Invoice(InvoiceDate) VALUES ('2011-03-21')");//try insert
        
    	ResultSet rs = con.select("Invoice"); //try select/get
	    while ( rs.next() )       
	    {     String id =  null;    
	    	  id = rs.getString(1); 
	    	  String datum = null;
	    	  datum = rs.getString(2);  
	    	  if(datum==null) datum="N/A";
	    	  System.out.println(id + ", " + datum );       
	    } 
	    rs.close(); 
	    */
	    
	    /*
	    //test for the ItemDao.insert(Item item)
    	insert an Item with Name,Price,Type,Storage
    	insertItem("test5",99,"",35);
    	*/
    	
        /*
	    //test for the ItemDao.delete() parm@ItemNr
    	itemDao.delete(12);
    	
	    //test for the ItemDao.updatePrice() parm@ItemNr,Price
    	itemDao.updatePrice(16,499);
    	
	    //test for the ItemDao.updateStorage() parm@ItemNr,Storage
    	itemDao.updateStorage(16,499);
           
	    //test for the ItemDao.queryAll()
    	tqueryAll();
    	
    	
	    //test for the ItemDao.queryBy() and this.tqueryBy
    	//parm@Name,Type,UpperPrice,LowerPrice
    	String string = "";
    	tqueryBy(string,string,999,299);
    	*/

    }
    /*
    public static void tqueryAll() throws Exception{
    	List<Item> listIt2 = new ArrayList<Item>();
	    listIt2 = itemDao.queryAll();
	    Iterator<Item> it = listIt2.iterator();
	    while(it.hasNext()){
	    	it.next().print();
	    }
    	System.out.println("Test Erfolgreich!" );
    	report(listIt2,"All Items");
    }
    
    //Method to generate a Report for Search-Results
    public static void tqueryBy(String s1,String s2, int i1, int i2) throws Exception{
    	List<Item> listIt1 = new ArrayList<Item>();
	    listIt1 = itemDao.queryBy(s1,s2,i1,i2);
	    Iterator<Item> it = listIt1.iterator();
	    while(it.hasNext()){
	    	it.next().print();
	    }
    	System.out.println("Test Erfolgreich!" );
    	report(listIt1,"Search Result");
    }
    
    //Method to generate Report-List of Items
    public static void report(List<Item> li,String s){
    	Iterator<Item> itli = li.iterator();
    	appFrame = new JFrame(s);
  		
  		//appFrame.setResizable(false);
  		appFrame.setVisible(true);
  		
    	JTextArea t1;
    	String str = "";
    	while(itli.hasNext()){
    		str = str + itli.next().report();
    	}
    	t1 = new JTextArea(str,10,15);
    	t1.setEditable(false);
    	Container c = appFrame.getContentPane();
    	JButton jbbClear;
    	c.add(jbbClear = new JButton("Clear"),"North");
    	//jbbClear.addActionListener();
    	c.add(new JScrollPane(t1),"Center");
    	appFrame.setSize(240,600);
    	System.out.println(str );
    }

    public static  void insertItem(String na,int pr,String tp,int st) throws Exception{
	    Item testItem = new Item();
	    testItem.setItem(0, na, pr, tp , st);
	    testItem.print();
	    itemDao.insert(testItem);
    } */
}
